|
mruby 4.0.0
mruby is the lightweight implementation of the Ruby language
|
#include <stdarg.h>#include <stdint.h>#include <stddef.h>#include <limits.h>#include "mrbconf.h"#include <mruby/common.h>#include <mruby/value.h>#include <mruby/gc.h>#include <mruby/version.h>#include <math.h>#include <float.h>#include <mruby/presym.h>

Go to the source code of this file.
Classes | |
| struct | mrb_callinfo |
| struct | mrb_context |
| struct | mrb_method_t |
| struct | mrb_cache_entry |
| struct | mrb_const_cache_entry |
| struct | mrb_state |
| struct | mrb_kwargs |
Macros | |
| #define | mrb_assert(p) |
| #define | mrb_assert_int_fit(t1, n, t2, max) |
| #define | _mrb_static_assert_cat0(a, b) |
| #define | _mrb_static_assert_cat(a, b) |
| #define | _mrb_static_assert_id(prefix) |
| #define | mrb_static_assert2(exp, str) |
| #define | mrb_static_assert1(exp) |
| #define | mrb_static_assert_expand(...) |
| #define | mrb_static_assert_selector(a, b, name, ...) |
| #define | mrb_static_assert(...) |
| The mrb_static_assert() macro function takes one or two arguments. | |
| #define | mrb_static_assert_powerof2(num) |
| #define | FLT_EPSILON (1.19209290e-07f) |
| #define | DBL_EPSILON ((double)2.22044604925031308085e-16L) |
| #define | LDBL_EPSILON (1.08420217248550443401e-19L) |
| #define | MRB_FLOAT_EPSILON DBL_EPSILON |
| #define | MRB_FIXED_STATE_ATEXIT_STACK_SIZE 5 |
| #define | MRB_TASK_CREATED MRB_FIBER_CREATED |
| #define | MRB_TASK_STOPPED MRB_FIBER_TERMINATED |
| #define | MRB_METHOD_CACHE_SIZE (1<<8) |
| #define | MRB_CONST_CACHE_SIZE (1<<6) |
| #define | mrb_exc_get(mrb, name) |
| #define | MRB_ARGS_REQ(n) |
| Function requires n arguments. | |
| #define | MRB_ARGS_OPT(n) |
| Function takes n optional arguments. | |
| #define | MRB_ARGS_ARG(n1, n2) |
| Function takes n1 mandatory arguments and n2 optional arguments. | |
| #define | MRB_ARGS_REST() |
| rest argument | |
| #define | MRB_ARGS_POST(n) |
| required arguments after rest | |
| #define | MRB_ARGS_KEY(n1, n2) |
| keyword arguments (n of keys, kdict) | |
| #define | MRB_ARGS_BLOCK() |
| Function takes a block argument. | |
| #define | MRB_ARGS_NOBLOCK() |
| Function does not accept a block (&nil). | |
| #define | MRB_ARGS_ANY() |
| Function accepts any number of arguments. | |
| #define | MRB_ARGS_NONE() |
| Function accepts no arguments. | |
| #define | mrb_strlen_lit(lit) |
| #define | mrb_intern_lit(mrb, lit) |
| #define | mrb_sym2name(mrb, sym) |
| #define | mrb_sym2name_len(mrb, sym, len) |
| #define | mrb_sym2str(mrb, sym) |
| #define | MRB_OBJ_ALLOC(mrb, tt, klass) |
| Allocates a Ruby object that matches the constant literal defined in enum mrb_vtype and returns a pointer to the corresponding C type. | |
| #define | mrb_str_new_lit(mrb, lit) |
| #define | mrb_str_new_frozen(mrb, p, len) |
| #define | mrb_str_new_cstr_frozen(mrb, p) |
| #define | mrb_str_new_static_frozen(mrb, p, len) |
| #define | mrb_str_new_lit_frozen(mrb, lit) |
| #define | mrb_utf8_from_locale(p, l) |
| #define | mrb_locale_from_utf8(p, l) |
| #define | mrb_locale_free(p) |
| #define | mrb_utf8_free(p) |
| #define | MRB_OPEN_FAILURE(mrb) |
| Check if mrb_open() failed. | |
| #define | MRB_OPEN_SUCCESS(mrb) |
| Check if mrb_open() succeeded. | |
| #define | mrb_toplevel_run_keep(m, p, k) |
| #define | mrb_toplevel_run(m, p) |
| #define | mrb_context_run(m, p, s, k) |
| #define | mrb_as_float(mrb, x) |
| #define | mrb_to_float(mrb, val) |
| #define | MRB_RECURSIVE_P(mrb, mid, obj1, obj2) |
| #define | MRB_RECURSIVE_UNARY_P(mrb, mid, obj) |
| #define | MRB_RECURSIVE_BINARY_P(mrb, mid, obj1, obj2) |
| #define | MRB_RECURSIVE_FUNC_P(mrb, mid, obj) |
| #define | MRB_RECURSIVE_BINARY_FUNC_P(mrb, mid, obj1, obj2) |
| #define | mrb_gc_arena_save(mrb) |
| #define | mrb_gc_arena_restore(mrb, idx) |
| #define | mrb_gc_mark_value(mrb, val) |
| #define | mrb_field_write_barrier_value(mrb, obj, val) |
| #define | mrb_convert_type(mrb, val, type, tname, method) |
| #define | mrb_check_convert_type(mrb, val, type, tname, method) |
| #define | ISASCII(c) |
| #define | ISPRINT(c) |
| #define | ISSPACE(c) |
| #define | ISUPPER(c) |
| #define | ISLOWER(c) |
| #define | ISALPHA(c) |
| #define | ISDIGIT(c) |
| #define | ISXDIGIT(c) |
| #define | ISALNUM(c) |
| #define | ISBLANK(c) |
| #define | ISCNTRL(c) |
| #define | TOUPPER(c) |
| #define | TOLOWER(c) |
| #define | MRB_ERROR_SYM(sym) |
| #define | E_EXCEPTION mrb->eException_class |
| #define | E_STANDARD_ERROR mrb->eStandardError_class |
| #define | E_RUNTIME_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(RuntimeError)) |
| #define | E_TYPE_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(TypeError)) |
| #define | E_ZERODIV_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(ZeroDivisionError)) |
| #define | E_ARGUMENT_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(ArgumentError)) |
| #define | E_INDEX_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(IndexError)) |
| #define | E_RANGE_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(RangeError)) |
| #define | E_NAME_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(NameError)) |
| #define | E_NOMETHOD_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(NoMethodError)) |
| #define | E_SCRIPT_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(ScriptError)) |
| #define | E_SYNTAX_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(SyntaxError)) |
| #define | E_LOCALJUMP_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(LocalJumpError)) |
| #define | E_REGEXP_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(RegexpError)) |
| #define | E_FROZEN_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(FrozenError)) |
| #define | E_NOTIMP_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(NotImplementedError)) |
| #define | E_KEY_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(KeyError)) |
| #define | E_FLOATDOMAIN_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(FloatDomainError)) |
| #define | mrb_string_type(mrb, str) |
| #define | mrb_to_str(mrb, str) |
| #define | mrb_str_to_str(mrb, str) |
| #define | mrb_as_int(mrb, val) |
| #define | mrb_to_integer(mrb, val) |
| #define | mrb_to_int(mrb, val) |
| #define | mrb_int(mrb, val) |
| #define | E_FIBER_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(FiberError)) |
| FiberError reference. | |
| #define | mrb_alloca(mrb, size) |
| #define | mrb_int_hash_func(mrb, key) |
| #define | MRB_UNIQNAME(name) |
| #define | MRB_UNIQNAME_1(name, line) |
| #define | MRB_UNIQNAME_2(name, line) |
Typedefs | |
| typedef struct mrb_state | mrb_state |
| typedef uint8_t | mrb_code |
| mruby C API entry point | |
| typedef uint32_t | mrb_aspec |
| typedef struct mrb_irep | mrb_irep |
| typedef mrb_value(* | mrb_func_t) (mrb_state *mrb, mrb_value self) |
| Function pointer type for a function callable by mruby. | |
| typedef void(* | mrb_atexit_func) (mrb_state *) |
| typedef const char * | mrb_args_format |
| Format specifiers for {mrb_get_args} function. | |
| typedef struct mrb_kwargs | mrb_kwargs |
| Get keyword arguments by mrb_get_args() with : specifier. | |
Enumerations | |
| enum | mrb_fiber_state { MRB_FIBER_CREATED = 0 , MRB_FIBER_RUNNING , MRB_FIBER_RESUMED , MRB_FIBER_SUSPENDED , MRB_FIBER_TRANSFERRED , MRB_FIBER_TERMINATED } |
Functions | |
| struct RClass * | mrb_define_class (mrb_state *mrb, const char *name, struct RClass *super) |
| Defines a new class. | |
| struct RClass * | mrb_define_class_id (mrb_state *mrb, mrb_sym name, struct RClass *super) |
| struct RClass * | mrb_define_module (mrb_state *mrb, const char *name) |
| Defines a new module. | |
| struct RClass * | mrb_define_module_id (mrb_state *mrb, mrb_sym name) |
| mrb_value | mrb_singleton_class (mrb_state *mrb, mrb_value val) |
| Returns the singleton class of an object. | |
| struct RClass * | mrb_singleton_class_ptr (mrb_state *mrb, mrb_value val) |
| Returns the singleton class of an object. | |
| void | mrb_include_module (mrb_state *mrb, struct RClass *cla, struct RClass *included) |
| Include a module in another class or module. | |
| void | mrb_prepend_module (mrb_state *mrb, struct RClass *cla, struct RClass *prepended) |
| Prepends a module in another class or module. | |
| void | mrb_define_method (mrb_state *mrb, struct RClass *cla, const char *name, mrb_func_t func, mrb_aspec aspec) |
| Defines a global function in Ruby. | |
| void | mrb_define_method_id (mrb_state *mrb, struct RClass *c, mrb_sym mid, mrb_func_t func, mrb_aspec aspec) |
| void | mrb_define_private_method (mrb_state *mrb, struct RClass *cla, const char *name, mrb_func_t func, mrb_aspec aspec) |
| void | mrb_define_private_method_id (mrb_state *mrb, struct RClass *c, mrb_sym mid, mrb_func_t func, mrb_aspec aspec) |
| void | mrb_define_class_method (mrb_state *mrb, struct RClass *cla, const char *name, mrb_func_t fun, mrb_aspec aspec) |
| Defines a class method. | |
| void | mrb_define_class_method_id (mrb_state *mrb, struct RClass *cla, mrb_sym name, mrb_func_t fun, mrb_aspec aspec) |
| void | mrb_define_singleton_method (mrb_state *mrb, struct RObject *cla, const char *name, mrb_func_t fun, mrb_aspec aspec) |
| Defines a singleton method. | |
| void | mrb_define_singleton_method_id (mrb_state *mrb, struct RObject *cla, mrb_sym name, mrb_func_t fun, mrb_aspec aspec) |
| void | mrb_define_module_function (mrb_state *mrb, struct RClass *cla, const char *name, mrb_func_t fun, mrb_aspec aspec) |
| Defines a module function. | |
| void | mrb_define_module_function_id (mrb_state *mrb, struct RClass *cla, mrb_sym name, mrb_func_t fun, mrb_aspec aspec) |
| void | mrb_define_const (mrb_state *mrb, struct RClass *cla, const char *name, mrb_value val) |
| Defines a constant. | |
| void | mrb_define_const_id (mrb_state *mrb, struct RClass *cla, mrb_sym name, mrb_value val) |
| void | mrb_undef_method (mrb_state *mrb, struct RClass *cla, const char *name) |
| Undefines a method. | |
| void | mrb_undef_method_id (mrb_state *, struct RClass *, mrb_sym) |
| void | mrb_undef_class_method (mrb_state *mrb, struct RClass *cls, const char *name) |
| Undefine a class method. | |
| void | mrb_undef_class_method_id (mrb_state *mrb, struct RClass *cls, mrb_sym name) |
| mrb_value | mrb_obj_new (mrb_state *mrb, struct RClass *c, mrb_int argc, const mrb_value *argv) |
| Initialize a new object instance of c class. | |
| static mrb_value | mrb_class_new_instance (mrb_state *mrb, mrb_int argc, const mrb_value *argv, struct RClass *c) |
| struct RClass * | mrb_class_new (mrb_state *mrb, struct RClass *super) |
| Creates a new instance of Class, Class. | |
| struct RClass * | mrb_module_new (mrb_state *mrb) |
| Creates a new module, Module. | |
| mrb_bool | mrb_class_defined (mrb_state *mrb, const char *name) |
| Returns an mrb_bool. | |
| mrb_bool | mrb_class_defined_id (mrb_state *mrb, mrb_sym name) |
| struct RClass * | mrb_class_get (mrb_state *mrb, const char *name) |
| Gets a class. | |
| struct RClass * | mrb_class_get_id (mrb_state *mrb, mrb_sym name) |
| struct RClass * | mrb_exc_get_id (mrb_state *mrb, mrb_sym name) |
| Gets a exception class. | |
| mrb_bool | mrb_class_defined_under (mrb_state *mrb, struct RClass *outer, const char *name) |
| Returns an mrb_bool. | |
| mrb_bool | mrb_class_defined_under_id (mrb_state *mrb, struct RClass *outer, mrb_sym name) |
| struct RClass * | mrb_class_get_under (mrb_state *mrb, struct RClass *outer, const char *name) |
| Gets a child class. | |
| struct RClass * | mrb_class_get_under_id (mrb_state *mrb, struct RClass *outer, mrb_sym name) |
| struct RClass * | mrb_module_get (mrb_state *mrb, const char *name) |
| Gets a module. | |
| struct RClass * | mrb_module_get_id (mrb_state *mrb, mrb_sym name) |
| struct RClass * | mrb_module_get_under (mrb_state *mrb, struct RClass *outer, const char *name) |
| Gets a module defined under another module. | |
| struct RClass * | mrb_module_get_under_id (mrb_state *mrb, struct RClass *outer, mrb_sym name) |
| void | mrb_notimplement (mrb_state *) |
| mrb_value | mrb_notimplement_m (mrb_state *, mrb_value) |
| mrb_value | mrb_obj_itself (mrb_state *, mrb_value) |
| mrb_value | mrb_obj_dup (mrb_state *mrb, mrb_value obj) |
| Duplicate an object. | |
| mrb_bool | mrb_obj_respond_to (mrb_state *mrb, struct RClass *c, mrb_sym mid) |
| Returns true if obj responds to the given method. | |
| struct RClass * | mrb_define_class_under (mrb_state *mrb, struct RClass *outer, const char *name, struct RClass *super) |
| Defines a new class under a given module. | |
| struct RClass * | mrb_define_class_under_id (mrb_state *mrb, struct RClass *outer, mrb_sym name, struct RClass *super) |
| struct RClass * | mrb_define_module_under (mrb_state *mrb, struct RClass *outer, const char *name) |
| struct RClass * | mrb_define_module_under_id (mrb_state *mrb, struct RClass *outer, mrb_sym name) |
| mrb_int | mrb_get_args (mrb_state *mrb, mrb_args_format format,...) |
| Retrieve arguments from mrb_state. | |
| mrb_int | mrb_get_args_a (mrb_state *mrb, mrb_args_format format, void **ptr) |
| Array version of mrb_get_args(). | |
| static mrb_sym | mrb_get_mid (mrb_state *mrb) |
| mrb_int | mrb_get_argc (mrb_state *mrb) |
| Retrieve number of arguments from mrb_state. | |
| const mrb_value * | mrb_get_argv (mrb_state *mrb) |
| Retrieve an array of arguments from mrb_state. | |
| mrb_value | mrb_get_arg1 (mrb_state *mrb) |
| Retrieve the first and only argument from mrb_state. | |
| mrb_bool | mrb_block_given_p (mrb_state *mrb) |
| Check if a block argument is given from mrb_state. | |
| mrb_value | mrb_funcall (mrb_state *mrb, mrb_value val, const char *name, mrb_int argc,...) |
| Call existing Ruby functions. | |
| mrb_value | mrb_funcall_id (mrb_state *mrb, mrb_value val, mrb_sym mid, mrb_int argc,...) |
| Calls a method on an object using a method ID. | |
| mrb_value | mrb_funcall_argv (mrb_state *mrb, mrb_value val, mrb_sym name, mrb_int argc, const mrb_value *argv) |
| Call existing Ruby functions. | |
| static mrb_value | mrb_funcall_argv1 (mrb_state *mrb, mrb_value val, mrb_sym name, mrb_value a1) |
| static mrb_value | mrb_funcall_argv2 (mrb_state *mrb, mrb_value val, mrb_sym name, mrb_value a1, mrb_value a2) |
| mrb_value | mrb_funcall_with_block (mrb_state *mrb, mrb_value val, mrb_sym name, mrb_int argc, const mrb_value *argv, mrb_value block) |
| Call existing Ruby functions with a block. | |
| mrb_sym | mrb_intern_cstr (mrb_state *mrb, const char *str) |
| Create a symbol from C string. | |
| mrb_sym | mrb_intern (mrb_state *, const char *, size_t) |
| mrb_sym | mrb_intern_static (mrb_state *, const char *, size_t) |
| mrb_sym | mrb_intern_str (mrb_state *, mrb_value) |
| mrb_sym | mrb_intern_check_cstr (mrb_state *, const char *) |
| mrb_sym | mrb_intern_check (mrb_state *, const char *, size_t) |
| mrb_sym | mrb_intern_check_str (mrb_state *, mrb_value) |
| mrb_value | mrb_check_intern_cstr (mrb_state *, const char *) |
| mrb_value | mrb_check_intern (mrb_state *, const char *, size_t) |
| mrb_value | mrb_check_intern_str (mrb_state *, mrb_value) |
| const char * | mrb_sym_name (mrb_state *, mrb_sym) |
| const char * | mrb_sym_name_len (mrb_state *, mrb_sym, mrb_int *) |
| const char * | mrb_sym_dump (mrb_state *, mrb_sym) |
| mrb_value | mrb_sym_str (mrb_state *, mrb_sym) |
| void * | mrb_malloc (mrb_state *, size_t) |
| void * | mrb_calloc (mrb_state *, size_t, size_t) |
| void * | mrb_realloc (mrb_state *, void *, size_t) |
| void * | mrb_realloc_simple (mrb_state *, void *, size_t) |
| void * | mrb_malloc_simple (mrb_state *, size_t) |
| struct RBasic * | mrb_obj_alloc (mrb_state *, enum mrb_vtype, struct RClass *) |
| void | mrb_free (mrb_state *, void *) |
| mrb_value | mrb_str_new (mrb_state *mrb, const char *p, mrb_int len) |
| mrb_value | mrb_str_new_cstr (mrb_state *, const char *) |
| Turns a C string into a Ruby string value. | |
| mrb_value | mrb_str_new_static (mrb_state *mrb, const char *p, mrb_int len) |
| mrb_value | mrb_obj_freeze (mrb_state *, mrb_value) |
| mrb_state * | mrb_open (void) |
| Creates new mrb_state. | |
| mrb_state * | mrb_open_core (void) |
| Create new mrb_state with just the mruby core. | |
| void | mrb_close (mrb_state *mrb) |
| Closes and frees a mrb_state. | |
| void | mrb_method_cache_clear (mrb_state *mrb) |
| void | mrb_const_cache_clear (mrb_state *mrb) |
| void * | mrb_basic_alloc_func (void *, size_t) |
| The memory allocation function. | |
| mrb_value | mrb_top_self (mrb_state *mrb) |
| mrb_value | mrb_top_run (mrb_state *mrb, const struct RProc *proc, mrb_value self, mrb_int stack_keep) |
| Enter the mruby VM and execute the proc. | |
| mrb_value | mrb_vm_run (mrb_state *mrb, const struct RProc *proc, mrb_value self, mrb_int stack_keep) |
| Executes a mruby bytecode sequence (iseq) within the VM. | |
| mrb_value | mrb_vm_exec (mrb_state *mrb, const struct RProc *proc, const mrb_code *iseq) |
| Executes a sequence of mruby bytecode instructions. | |
| void | mrb_p (mrb_state *, mrb_value) |
| mrb_int | mrb_obj_id (mrb_value obj) |
| mrb_sym | mrb_obj_to_sym (mrb_state *mrb, mrb_value name) |
| mrb_bool | mrb_obj_eq (mrb_state *mrb, mrb_value a, mrb_value b) |
| mrb_bool | mrb_obj_equal (mrb_state *mrb, mrb_value a, mrb_value b) |
| mrb_bool | mrb_equal (mrb_state *mrb, mrb_value obj1, mrb_value obj2) |
| mrb_value | mrb_ensure_float_type (mrb_state *mrb, mrb_value val) |
| mrb_value | mrb_inspect (mrb_state *mrb, mrb_value obj) |
| mrb_bool | mrb_eql (mrb_state *mrb, mrb_value obj1, mrb_value obj2) |
| mrb_int | mrb_cmp (mrb_state *mrb, mrb_value obj1, mrb_value obj2) |
| Compares two mrb_value objects (obj1 and obj2). | |
| mrb_bool | mrb_recursive_method_p (mrb_state *mrb, mrb_sym mid, mrb_value obj1, mrb_value obj2) |
| mrb_bool | mrb_recursive_func_p (mrb_state *mrb, mrb_sym mid, mrb_value obj1, mrb_value obj2) |
| Check if a C function call is recursive. | |
| void | mrb_garbage_collect (mrb_state *) |
| void | mrb_full_gc (mrb_state *) |
| void | mrb_incremental_gc (mrb_state *) |
| void | mrb_gc_mark (mrb_state *, struct RBasic *) |
| void | mrb_field_write_barrier (mrb_state *, struct RBasic *, struct RBasic *) |
| void | mrb_write_barrier (mrb_state *, struct RBasic *) |
| mrb_value | mrb_type_convert (mrb_state *mrb, mrb_value val, enum mrb_vtype type, mrb_sym method) |
| mrb_value | mrb_type_convert_check (mrb_state *mrb, mrb_value val, enum mrb_vtype type, mrb_sym method) |
| mrb_value | mrb_any_to_s (mrb_state *mrb, mrb_value obj) |
| const char * | mrb_obj_classname (mrb_state *mrb, mrb_value obj) |
| struct RClass * | mrb_obj_class (mrb_state *mrb, mrb_value obj) |
| mrb_value | mrb_class_path (mrb_state *mrb, struct RClass *c) |
| mrb_bool | mrb_obj_is_kind_of (mrb_state *mrb, mrb_value obj, struct RClass *c) |
| mrb_value | mrb_obj_inspect (mrb_state *mrb, mrb_value self) |
| mrb_value | mrb_obj_clone (mrb_state *mrb, mrb_value self) |
| mrb_value | mrb_exc_new (mrb_state *mrb, struct RClass *c, const char *ptr, mrb_int len) |
| void | mrb_exc_raise (mrb_state *mrb, mrb_value exc) |
| void | mrb_raise (mrb_state *mrb, struct RClass *c, const char *msg) |
| void | mrb_raisef (mrb_state *mrb, struct RClass *c, const char *fmt,...) |
| void | mrb_name_error (mrb_state *mrb, mrb_sym id, const char *fmt,...) |
| void | mrb_frozen_error (mrb_state *mrb, void *frozen_obj) |
| void | mrb_argnum_error (mrb_state *mrb, mrb_int argc, int min, int max) |
| void | mrb_warn (mrb_state *mrb, const char *fmt,...) |
| void | mrb_bug (mrb_state *mrb, const char *mesg) |
| void | mrb_print_backtrace (mrb_state *mrb) |
| void | mrb_print_error (mrb_state *mrb) |
| mrb_value | mrb_vformat (mrb_state *mrb, const char *format, va_list ap) |
| mrb_value | mrb_yield (mrb_state *mrb, mrb_value b, mrb_value arg) |
| Yields to a block with a single argument. | |
| mrb_value | mrb_yield_argv (mrb_state *mrb, mrb_value b, mrb_int argc, const mrb_value *argv) |
| Yields to a block with an array of arguments. | |
| mrb_value | mrb_yield_with_class (mrb_state *mrb, mrb_value b, mrb_int argc, const mrb_value *argv, mrb_value self, struct RClass *c) |
| Yields to a block with a specific self object and class context. | |
| mrb_value | mrb_yield_cont (mrb_state *mrb, mrb_value b, mrb_value self, mrb_int argc, const mrb_value *argv) |
| void | mrb_gc_protect (mrb_state *mrb, mrb_value obj) |
| void | mrb_gc_register (mrb_state *mrb, mrb_value obj) |
| void | mrb_gc_unregister (mrb_state *mrb, mrb_value obj) |
| mrb_value | mrb_ensure_array_type (mrb_state *mrb, mrb_value self) |
| mrb_value | mrb_check_array_type (mrb_state *mrb, mrb_value self) |
| mrb_value | mrb_ensure_hash_type (mrb_state *mrb, mrb_value hash) |
| mrb_value | mrb_check_hash_type (mrb_state *mrb, mrb_value hash) |
| mrb_value | mrb_ensure_string_type (mrb_state *mrb, mrb_value str) |
| mrb_value | mrb_check_string_type (mrb_state *mrb, mrb_value str) |
| mrb_value | mrb_ensure_integer_type (mrb_state *mrb, mrb_value val) |
| mrb_value | mrb_ensure_int_type (mrb_state *mrb, mrb_value val) |
| void | mrb_check_type (mrb_state *mrb, mrb_value x, enum mrb_vtype t) |
| void | mrb_check_frozen (mrb_state *mrb, void *) |
| void | mrb_check_frozen_value (mrb_state *mrb, mrb_value v) |
| void | mrb_define_alias (mrb_state *mrb, struct RClass *c, const char *a, const char *b) |
| void | mrb_define_alias_id (mrb_state *mrb, struct RClass *c, mrb_sym a, mrb_sym b) |
| const char * | mrb_class_name (mrb_state *mrb, struct RClass *klass) |
| void | mrb_define_global_const (mrb_state *mrb, const char *name, mrb_value val) |
| mrb_value | mrb_attr_get (mrb_state *mrb, mrb_value obj, mrb_sym id) |
| mrb_bool | mrb_respond_to (mrb_state *mrb, mrb_value obj, mrb_sym mid) |
| mrb_bool | mrb_obj_is_instance_of (mrb_state *mrb, mrb_value obj, const struct RClass *c) |
| mrb_bool | mrb_func_basic_p (mrb_state *mrb, mrb_value obj, mrb_sym mid, mrb_func_t func) |
| mrb_value | mrb_fiber_new (mrb_state *mrb, const struct RProc *proc) |
| Create a new Fiber from proc object. | |
| mrb_value | mrb_fiber_resume (mrb_state *mrb, mrb_value fib, mrb_int argc, const mrb_value *argv) |
| Resume a Fiber. | |
| mrb_value | mrb_fiber_yield (mrb_state *mrb, mrb_int argc, const mrb_value *argv) |
| Yield a Fiber. | |
| mrb_value | mrb_fiber_alive_p (mrb_state *mrb, mrb_value fib) |
| Check if a Fiber is alive. | |
| void | mrb_stack_extend (mrb_state *, mrb_int) |
| Extends the VM stack. | |
| void * | mrb_temp_alloc (mrb_state *mrb, size_t) |
| void | mrb_state_atexit (mrb_state *mrb, mrb_atexit_func func) |
| void | mrb_show_version (mrb_state *mrb) |
| void | mrb_show_copyright (mrb_state *mrb) |
| mrb_value | mrb_format (mrb_state *mrb, const char *format,...) |
| #define _mrb_static_assert_cat | ( | a, | |
| b ) |
| #define _mrb_static_assert_cat0 | ( | a, | |
| b ) |
| #define _mrb_static_assert_id | ( | prefix | ) |
| #define E_FIBER_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(FiberError)) |
FiberError reference.
Implemented in mruby-fiber
| #define ISALNUM | ( | c | ) |
| #define ISALPHA | ( | c | ) |
| #define ISASCII | ( | c | ) |
| #define ISBLANK | ( | c | ) |
| #define ISCNTRL | ( | c | ) |
| #define ISDIGIT | ( | c | ) |
| #define ISLOWER | ( | c | ) |
| #define ISPRINT | ( | c | ) |
| #define ISSPACE | ( | c | ) |
| #define ISUPPER | ( | c | ) |
| #define ISXDIGIT | ( | c | ) |
| #define mrb_alloca | ( | mrb, | |
| size ) |
| #define MRB_ARGS_ANY | ( | ) |
Function accepts any number of arguments.
| #define MRB_ARGS_ARG | ( | n1, | |
| n2 ) |
Function takes n1 mandatory arguments and n2 optional arguments.
| n1 | The number of required arguments. |
| n2 | The number of optional arguments. |
| #define MRB_ARGS_BLOCK | ( | ) |
| #define MRB_ARGS_KEY | ( | n1, | |
| n2 ) |
keyword arguments (n of keys, kdict)
| #define MRB_ARGS_NOBLOCK | ( | ) |
Function does not accept a block (&nil).
| #define MRB_ARGS_NONE | ( | ) |
Function accepts no arguments.
| #define MRB_ARGS_OPT | ( | n | ) |
Function takes n optional arguments.
| n | The number of optional arguments. |
| #define MRB_ARGS_POST | ( | n | ) |
required arguments after rest
| #define MRB_ARGS_REQ | ( | n | ) |
Function requires n arguments.
| n | The number of required arguments. |
| #define MRB_ARGS_REST | ( | ) |
rest argument
| #define mrb_as_float | ( | mrb, | |
| x ) |
| #define mrb_as_int | ( | mrb, | |
| val ) |
| #define mrb_assert | ( | p | ) |
| #define mrb_assert_int_fit | ( | t1, | |
| n, | |||
| t2, | |||
| max ) |
| #define mrb_check_convert_type | ( | mrb, | |
| val, | |||
| type, | |||
| tname, | |||
| method ) |
| #define mrb_context_run | ( | m, | |
| p, | |||
| s, | |||
| k ) |
| #define mrb_convert_type | ( | mrb, | |
| val, | |||
| type, | |||
| tname, | |||
| method ) |
| #define MRB_ERROR_SYM | ( | sym | ) |
| #define mrb_exc_get | ( | mrb, | |
| name ) |
| #define mrb_field_write_barrier_value | ( | mrb, | |
| obj, | |||
| val ) |
| #define mrb_gc_arena_restore | ( | mrb, | |
| idx ) |
| #define mrb_gc_arena_save | ( | mrb | ) |
| #define mrb_gc_mark_value | ( | mrb, | |
| val ) |
| #define mrb_int | ( | mrb, | |
| val ) |
| #define mrb_int_hash_func | ( | mrb, | |
| key ) |
| #define mrb_intern_lit | ( | mrb, | |
| lit ) |
| #define mrb_locale_from_utf8 | ( | p, | |
| l ) |
| #define MRB_OBJ_ALLOC | ( | mrb, | |
| tt, | |||
| klass ) |
Allocates a Ruby object that matches the constant literal defined in enum mrb_vtype and returns a pointer to the corresponding C type.
| mrb | The current mruby state |
| tt | The constant literal of enum mrb_vtype |
| klass | A Class object |
| #define MRB_OPEN_FAILURE | ( | mrb | ) |
Check if mrb_open() failed.
| mrb | Pointer returned from mrb_open() or mrb_open_core(). |
| #define MRB_OPEN_SUCCESS | ( | mrb | ) |
Check if mrb_open() succeeded.
| mrb | Pointer returned from mrb_open() or mrb_open_core(). |
| #define MRB_RECURSIVE_BINARY_FUNC_P | ( | mrb, | |
| mid, | |||
| obj1, | |||
| obj2 ) |
| #define MRB_RECURSIVE_BINARY_P | ( | mrb, | |
| mid, | |||
| obj1, | |||
| obj2 ) |
| #define MRB_RECURSIVE_FUNC_P | ( | mrb, | |
| mid, | |||
| obj ) |
| #define MRB_RECURSIVE_P | ( | mrb, | |
| mid, | |||
| obj1, | |||
| obj2 ) |
| #define MRB_RECURSIVE_UNARY_P | ( | mrb, | |
| mid, | |||
| obj ) |
| #define mrb_static_assert | ( | ... | ) |
The mrb_static_assert() macro function takes one or two arguments.
!!!c mrb_static_assert(expect_condition); mrb_static_assert(expect_condition, error_message);
| #define mrb_static_assert1 | ( | exp | ) |
| #define mrb_static_assert2 | ( | exp, | |
| str ) |
| #define mrb_static_assert_expand | ( | ... | ) |
| #define mrb_static_assert_powerof2 | ( | num | ) |
| #define mrb_static_assert_selector | ( | a, | |
| b, | |||
| name, | |||
| ... ) |
| #define mrb_str_new_cstr_frozen | ( | mrb, | |
| p ) |
| #define mrb_str_new_frozen | ( | mrb, | |
| p, | |||
| len ) |
| #define mrb_str_new_lit | ( | mrb, | |
| lit ) |
| #define mrb_str_new_lit_frozen | ( | mrb, | |
| lit ) |
| #define mrb_str_new_static_frozen | ( | mrb, | |
| p, | |||
| len ) |
| #define mrb_str_to_str | ( | mrb, | |
| str ) |
| #define mrb_string_type | ( | mrb, | |
| str ) |
| #define mrb_strlen_lit | ( | lit | ) |
| #define mrb_sym2name | ( | mrb, | |
| sym ) |
| #define mrb_sym2name_len | ( | mrb, | |
| sym, | |||
| len ) |
| #define mrb_sym2str | ( | mrb, | |
| sym ) |
| #define mrb_to_float | ( | mrb, | |
| val ) |
| #define mrb_to_int | ( | mrb, | |
| val ) |
| #define mrb_to_integer | ( | mrb, | |
| val ) |
| #define mrb_to_str | ( | mrb, | |
| str ) |
| #define mrb_toplevel_run | ( | m, | |
| p ) |
| #define mrb_toplevel_run_keep | ( | m, | |
| p, | |||
| k ) |
| #define MRB_UNIQNAME | ( | name | ) |
| #define MRB_UNIQNAME_1 | ( | name, | |
| line ) |
| #define MRB_UNIQNAME_2 | ( | name, | |
| line ) |
| #define mrb_utf8_from_locale | ( | p, | |
| l ) |
| #define TOLOWER | ( | c | ) |
| #define TOUPPER | ( | c | ) |
| typedef const char* mrb_args_format |
Format specifiers for {mrb_get_args} function.
Must be a C string composed of the following format specifiers:
| char | Ruby type | C types | Notes |
|---|---|---|---|
| o | {Object} | {mrb_value} | Could be used to retrieve any type of argument |
| C | {Class}/{Module} | {mrb_value} | when ! follows, the value may be nil |
| S | {String} | {mrb_value} | when ! follows, the value may be nil |
| A | {Array} | {mrb_value} | when ! follows, the value may be nil |
| H | {Hash} | {mrb_value} | when ! follows, the value may be nil |
| s | {String} | const char *, {mrb_int} | Receive two arguments; s! gives (NULL,0) for nil |
| z | {String} | const char * | NULL terminated string; z! gives NULL for nil |
| a | {Array} | const {mrb_value} *, {mrb_int} | Receive two arguments; a! gives (NULL,0) for nil |
| c | {Class}/{Module} | strcut RClass * | c! gives NULL for nil |
| f | {Integer}/{Float} | {mrb_float} | |
| i | {Integer}/{Float} | {mrb_int} | |
| b | boolean | {mrb_bool} | |
| n | {String}/{Symbol} | {mrb_sym} | |
| d | data | void *, {mrb_data_type} const | 2nd argument will be used to check data type so it won't be modified; when ! follows, the value may be nil |
| I | inline struct | void *, struct RClass | I! gives NULL for nil |
| & | block | {mrb_value} | &! raises exception if no block given. |
| * | rest arguments | const {mrb_value} *, {mrb_int} | Receive the rest of arguments as an array; *! avoid copy of the stack. |
| \| | optional | After this spec following specs would be optional. | |
| ? | optional given | {mrb_bool} | TRUE if preceding argument is given. Used to check optional argument is given. |
| : | keyword args | {mrb_kwargs} const | Get keyword arguments.
|
Immediately after format specifiers it can add format modifiers:
| char | Notes |
|---|---|
| ! | Switch to the alternate mode; The behaviour changes depending on the format specifier |
| + | Request a not frozen object; However, except nil value |
| typedef struct mrb_kwargs mrb_kwargs |
Get keyword arguments by mrb_get_args() with : specifier.
mrb_kwargs::num indicates that the total number of keyword values.
mrb_kwargs::required indicates that the specified number of keywords starting from the beginning of the mrb_sym array are required.
mrb_kwargs::table accepts a mrb_sym array of C.
mrb_kwargs::values is an object array of C, and the keyword argument corresponding to the mrb_sym array is assigned. Note that undef is assigned if there is no keyword argument corresponding over mrb_kwargs::required to mrb_kwargs::num.
mrb_kwargs::rest is the remaining keyword argument that can be accepted as **rest in Ruby. If NULL is specified, ArgumentError is raised when there is an undefined keyword.
Examples:
// def method(a: 1, b: 2)
mrb_int kw_num = 2;
mrb_int kw_required = 0;
mrb_sym kw_names[] = { mrb_intern_lit(mrb, "a"), mrb_intern_lit(mrb, "b") };
mrb_value kw_values[kw_num];
mrb_kwargs kwargs = { kw_num, kw_required, kw_names, kw_values, NULL };
mrb_get_args(mrb, ":", &kwargs);
if (mrb_undef_p(kw_values[0])) { kw_values[0] = mrb_fixnum_value(1); }
if (mrb_undef_p(kw_values[1])) { kw_values[1] = mrb_fixnum_value(2); }
// def method(str, x:, y: 2, z: "default string", **opts)
mrb_value str, kw_rest;
uint32_t kw_num = 3;
uint32_t kw_required = 1;
// `MRB_SYM()` is available via `mruby.h` (which includes `mruby/presym.h`).
// If the usage of `MRB_SYM()` is not desired, replace it with `mrb_intern_lit()`.
mrb_sym kw_names[] = { MRB_SYM(x), MRB_SYM(y), MRB_SYM(z) };
mrb_value kw_values[kw_num];
mrb_kwargs kwargs = { kw_num, kw_required, kw_names, kw_values, &kw_rest };
mrb_get_args(mrb, "S:", &str, &kwargs);
// or: mrb_get_args(mrb, ":S", &kwargs, &str);
if (mrb_undef_p(kw_values[1])) { kw_values[1] = mrb_fixnum_value(2); }
if (mrb_undef_p(kw_values[2])) { kw_values[2] = mrb_str_new_cstr(mrb, "default string"); }
|
extern |
The memory allocation function.
You can redefine this function for your own allocator.
Returns an mrb_bool.
True if class was defined, and false if the class was not defined.
Example: void mrb_example_gem_init(mrb_state* mrb) { struct RClass *example_class; mrb_bool cd;
example_class = mrb_define_class(mrb, "ExampleClass", mrb->object_class); cd = mrb_class_defined(mrb, "ExampleClass");
// If mrb_class_defined returns TRUE then puts "True" // If mrb_class_defined returns FALSE then puts "False" if (cd) { puts("True"); } else { puts("False"); } }
| mrb | The current mruby state. |
| name | A string representing the name of the class. |
|
extern |
Returns an mrb_bool.
True if inner class was defined, and false if the inner class was not defined.
Example: void mrb_example_gem_init(mrb_state* mrb) { struct RClass *example_outer, *example_inner; mrb_bool cd;
example_outer = mrb_define_module(mrb, "ExampleOuter");
example_inner = mrb_define_class_under(mrb, example_outer, "ExampleInner", mrb->object_class); cd = mrb_class_defined_under(mrb, example_outer, "ExampleInner");
// If mrb_class_defined_under returns TRUE then puts "True" // If mrb_class_defined_under returns FALSE then puts "False" if (cd) { puts("True"); } else { puts("False"); } }
| mrb | The current mruby state. |
| outer | The name of the outer class. |
| name | A string representing the name of the inner class. |
Gets a class.
| mrb | The current mruby state. |
| name | The name of the class. |
|
extern |
Gets a child class.
| mrb | The current mruby state. |
| outer | The name of the parent class. |
| name | The name of the class. |
Creates a new instance of Class, Class.
Example:
void
mrb_example_gem_init(mrb_state* mrb) {
struct RClass *example_class;
mrb_value obj;
example_class = mrb_class_new(mrb, mrb->object_class);
obj = mrb_obj_new(mrb, example_class, 0, NULL); // => #<#<Class:0x9a945b8>:0x9a94588>
mrb_p(mrb, obj); // => Kernel#p
}
| mrb | The current mruby state. |
| super | The super class or parent. |
|
inlinestatic |
|
extern |
Compares two mrb_value objects (obj1 and obj2).
| mrb | The mruby state. |
| obj1 | The first object. |
| obj2 | The second object. |
|
extern |
Defines a new class.
If you're creating a gem it may look something like this:
!!!c
void mrb_example_gem_init(mrb_state* mrb) {
struct RClass *example_class;
example_class = mrb_define_class(mrb, "Example_Class", mrb->object_class);
}
void mrb_example_gem_final(mrb_state* mrb) {
//free(TheAnimals);
}
| mrb | The current mruby state. |
| name | The name of the defined class. |
| super | The new class parent. |
|
extern |
Defines a class method.
Example:
# Ruby style
class Foo
def Foo.bar
end
end
// C style
mrb_value bar_method(mrb_state* mrb, mrb_value self){
return mrb_nil_value();
}
void mrb_example_gem_init(mrb_state* mrb){
struct RClass *foo;
foo = mrb_define_class(mrb, "Foo", mrb->object_class);
mrb_define_class_method(mrb, foo, "bar", bar_method, MRB_ARGS_NONE());
}
| mrb | The mruby state reference. |
| cla | The class where the class method will be defined. |
| name | The name of the class method being defined. |
| fun | The function pointer to the class method definition. |
| aspec | The method parameters declaration. |
|
extern |
Defines a new class under a given module.
| mrb | The current mruby state. |
| outer | Reference to the module under which the new class will be defined |
| name | The name of the defined class |
| super | The new class parent |
|
extern |
Defines a constant.
Example:
# Ruby style
class ExampleClass
AGE = 22
end
// C style
#include <stdio.h>
#include <mruby.h>
void
mrb_example_gem_init(mrb_state* mrb){
mrb_define_const(mrb, mrb->kernel_module, "AGE", mrb_fixnum_value(22));
}
mrb_value
mrb_example_gem_final(mrb_state* mrb){
}
| mrb | The mruby state reference. |
| cla | A class or module the constant is defined in. |
| name | The name of the constant being defined. |
| val | The value for the constant. |
|
extern |
Defines a global function in Ruby.
If you're creating a gem it may look something like this
Example:
mrb_value example_method(mrb_state* mrb, mrb_value self)
{
puts("Executing example command!");
return self;
}
void mrb_example_gem_init(mrb_state* mrb)
{
mrb_define_method(mrb, mrb->kernel_module, "example_method", example_method, MRB_ARGS_NONE());
}
| mrb | The mruby state reference. |
| cla | The class pointer where the method will be defined. |
| name | The name of the method being defined. |
| func | The function pointer to the method definition. |
| aspec | The method parameters declaration. |
Defines a new module.
| mrb | The current mruby state. |
| name | The name of the module. |
|
extern |
Defines a module function.
Example:
# Ruby style
module Foo
def Foo.bar
end
end
// C style
mrb_value bar_method(mrb_state* mrb, mrb_value self){
return mrb_nil_value();
}
void mrb_example_gem_init(mrb_state* mrb){
struct RClass *foo;
foo = mrb_define_module(mrb, "Foo");
mrb_define_module_function(mrb, foo, "bar", bar_method, MRB_ARGS_NONE());
}
| mrb | The mruby state reference. |
| cla | The module where the module function will be defined. |
| name | The name of the module function being defined. |
| fun | The function pointer to the module function definition. |
| aspec | The method parameters declaration. |
|
extern |
Defines a singleton method.
Gets a exception class.
| mrb | The current mruby state. |
| name | The name of the class. |
Check if a Fiber is alive.
Implemented in mruby-fiber
Create a new Fiber from proc object.
Implemented in mruby-fiber
|
extern |
Resume a Fiber.
Implemented in mruby-fiber
Switches to the specified fiber and executes. Like the Fiber#resume method.
Yield a Fiber.
Implemented in mruby-fiber
Passes control to the caller fiber of the running fiber. Like the Fiber.yield method.
return mrb_fiber_yield(mrb, argc, argv);
|
extern |
Call existing Ruby functions.
Example:
#include <stdio.h>
#include <mruby.h>
#include <mruby/compile.h>
int
main()
{
mrb_int i = 99;
mrb_state *mrb = mrb_open();
if (!mrb) { }
FILE *fp = fopen("test.rb","r");
mrb_value obj = mrb_load_file(mrb,fp);
mrb_funcall(mrb, obj, "method_name", 1, mrb_fixnum_value(i));
mrb_funcall_id(mrb, obj, MRB_SYM(method_name), 1, mrb_fixnum_value(i));
fclose(fp);
mrb_close(mrb);
}
| mrb | The current mruby state. |
| val | A reference to an mruby value. |
| name | The name of the method. |
| argc | The number of arguments the method has. |
| ... | Variadic values(not type safe!). |
Call existing Ruby functions.
This function invokes a method identified by its name on the self object, passing the given arguments.
| mrb | The mruby state. |
| self | The receiver object of the method call. |
| name | The name of the method to call (C string). |
| argc | The number of arguments to pass to the method. |
| ... | The variable arguments to pass to the method. Each argument must be of type mrb_value. |
|
extern |
Call existing Ruby functions.
This is basically the type safe version of mrb_funcall.
#include <stdio.h>
#include <mruby.h>
#include <mruby/compile.h>
int
main()
{
mrb_state *mrb = mrb_open();
mrb_value obj = mrb_fixnum_value(1);
if (!mrb) { }
FILE *fp = fopen("test.rb","r");
mrb_value obj = mrb_load_file(mrb,fp);
mrb_funcall_argv(mrb, obj, MRB_SYM(method_name), 1, &obj); // Calling Ruby function from test.rb.
fclose(fp);
mrb_close(mrb);
}
| mrb | The current mruby state. |
| val | A reference to an mruby value. |
| name_sym | The symbol representing the method. |
| argc | The number of arguments the method has. |
| obj | Pointer to the object. |
Call existing Ruby functions.
This function is similar to mrb_funcall_with_block but takes arguments as a C array (argv) and does not take an explicit block argument. If a block is needed, mrb_funcall_with_block should be used. This function is essentially a convenience wrapper around mrb_funcall_with_block with mrb_nil_value() for the block.
| mrb | The mruby state. |
| self | The receiver object of the method call. |
| mid | The symbol ID of the method to call. |
| argc | The number of arguments in argv. |
| argv | A pointer to an array of mrb_value arguments. |
Calls a method on an object using a method ID.
This function invokes a method identified by its symbol ID (mid) on the self object, passing the given arguments. Using a method ID can be more efficient than using a string name if the method is called frequently, as it avoids repeated string-to-symbol lookups.
| mrb | The mruby state. |
| self | The receiver object of the method call. |
| mid | The symbol ID of the method to call. |
| argc | The number of arguments to pass to the method. |
| ... | The variable arguments to pass to the method. Each argument must be of type mrb_value. |
|
extern |
Call existing Ruby functions with a block.
Call existing Ruby functions with a block.
This function invokes a method identified by its symbol ID (mid) on the self object, passing the given arguments (argv) and a block (blk).
| mrb | The mruby state. |
| self | The receiver object of the method call. |
| mid | The symbol ID of the method to call. |
| argc | The number of arguments in argv. |
| argv | A pointer to an array of mrb_value arguments. |
| blk | The block to pass to the method. If no block is to be passed, use mrb_nil_value(). If blk is not nil and not a proc, it will be converted to a proc using to_proc. |
Retrieve the first and only argument from mrb_state.
Raises ArgumentError unless the number of arguments is exactly one.
Correctly handles *splat arguments.
|
extern |
Retrieve number of arguments from mrb_state.
Correctly handles *splat arguments.
|
extern |
Retrieve arguments from mrb_state.
| mrb | The current mruby state. |
| format | is a list of format specifiers |
| ... | The passing variadic arguments must be a pointer of retrieving type. |
|
extern |
Array version of mrb_get_args().
| ptr | Array of void*, in the same order as the varargs version. |
Retrieve an array of arguments from mrb_state.
Correctly handles *splat arguments.
Include a module in another class or module.
Equivalent to:
module B include A end
| mrb | The current mruby state. |
| cla | A reference to module or a class. |
| included | A reference to the module to be included. |
Create a symbol from C string.
But usually it's better to use MRB_SYM, MRB_OPSYM, MRB_CVSYM, MRB_IVSYM, MRB_GVSYM, MRB_SYM_B, MRB_SYM_Q, MRB_SYM_E macros.
Example:
# Ruby style: :pizza # => :pizza // C style: mrb_sym sym1 = mrb_intern_lit(mrb, "pizza"); // => :pizza mrb_sym sym2 = MRB_SYM(pizza); // => :pizza mrb_sym sym3 = MRB_SYM_Q(pizza); // => :pizza?
| mrb | The current mruby state. |
| str | The string to be symbolized |
Gets a module.
| mrb | The current mruby state. |
| name | The name of the module. |
|
extern |
Gets a module defined under another module.
| mrb | The current mruby state. |
| outer | The name of the outer module. |
| name | The name of the module. |
Duplicate an object.
Equivalent to: Object#dup
| mrb | The current mruby state. |
| obj | Object to be duplicate. |
|
extern |
Initialize a new object instance of c class.
Example:
# Ruby style
class ExampleClass
end
p ExampleClass # => #<ExampleClass:0x9958588>
// C style
#include <stdio.h>
#include <mruby.h>
void
mrb_example_gem_init(mrb_state* mrb) {
struct RClass *example_class;
mrb_value obj;
example_class = mrb_define_class(mrb, "ExampleClass", mrb->object_class); # => class ExampleClass; end
obj = mrb_obj_new(mrb, example_class, 0, NULL); # => ExampleClass.new
mrb_p(mrb, obj); // => Kernel#p
}
| mrb | The current mruby state. |
| c | Reference to the class of the new object. |
| argc | Number of arguments in argv |
| argv | Array of mrb_value to initialize the object |
Returns true if obj responds to the given method.
If the method was defined for that class it returns true, it returns false otherwise.
Example:
# Ruby style
class ExampleClass
def example_method
end
end
ExampleClass.new.respond_to?(:example_method) # => true
// C style
void
mrb_example_gem_init(mrb_state* mrb) {
struct RClass *example_class;
mrb_sym mid;
mrb_bool obj_resp;
example_class = mrb_define_class(mrb, "ExampleClass", mrb->object_class);
mrb_define_method(mrb, example_class, "example_method", exampleMethod, MRB_ARGS_NONE());
mid = mrb_intern_str(mrb, mrb_str_new_lit(mrb, "example_method" ));
obj_resp = mrb_obj_respond_to(mrb, example_class, mid); // => TRUE (true in Ruby world)
// If mrb_obj_respond_to returns TRUE then puts "True"
// If mrb_obj_respond_to returns FALSE then puts "False"
if (obj_resp) {
puts("True");
}
else {
puts("False");
}
}
| mrb | The current mruby state. |
| c | A reference to a class. |
| mid | A symbol referencing a method id. |
|
extern |
|
extern |
Prepends a module in another class or module.
Equivalent to: module B prepend A end
| mrb | The current mruby state. |
| cla | A reference to module or a class. |
| prepended | A reference to the module to be prepended. |
|
extern |
Check if a C function call is recursive.
Like mrb_recursive_method_p, but starts from ci[-2] to skip the immediate parent frame. Use this from C functions implementing Ruby methods that can be overridden with super calls.
Returns the singleton class of an object.
Raises a TypeError exception for immediate values.
Returns the singleton class of an object.
Returns NULL for immediate values,
|
extern |
Extends the VM stack.
This function extends the virtual machine stack to accommodate more values. If the current stack size is insufficient, it reallocates the stack with a larger size.
| mrb | The mruby state. |
| room | The additional number of mrb_value slots required. |
|
extern |
Enter the mruby VM and execute the proc.
| mrb | The current mruby state. |
| proc | An object containing irep. If supplied an object containing anything other than irep, it will probably crash. |
| self | self on the execution context of proc. |
| stack_keep | Specifies the number of values to hold from the stack top. Values on the stack outside this range will be initialized to nil. |
Enter the mruby VM and execute the proc.
This function is used to execute a proc (like a script loaded from a file or a string) at the top level of the mruby environment. It's similar to mrb_vm_run but is specifically designed for top-level execution.
It ensures that if there's an existing callinfo stack, the new execution is pushed on top with CINFO_SKIP, indicating it's a new, distinct execution context rather than a nested call from within the VM.
| mrb | The mruby state. |
| proc | The RProc object (representing the script or code) to execute. |
| self | The self object for this top-level execution. Typically, this is the main top_self object in mruby. |
| stack_keep | The number of values to preserve on the stack. For top-level execution, this is often 0 or a small number to set up initial local variables if any. |
Undefine a class method.
Example:
# Ruby style
class ExampleClass
def self.example_method
"example"
end
end
ExampleClass.example_method
// C style
#include <stdio.h>
#include <mruby.h>
mrb_value
mrb_example_method(mrb_state *mrb){
return mrb_str_new_lit(mrb, "example");
}
void
mrb_example_gem_init(mrb_state* mrb){
struct RClass *example_class;
example_class = mrb_define_class(mrb, "ExampleClass", mrb->object_class);
mrb_define_class_method(mrb, example_class, "example_method", mrb_example_method, MRB_ARGS_NONE());
mrb_undef_class_method(mrb, example_class, "example_method");
}
void
mrb_example_gem_final(mrb_state* mrb){
}
| mrb | The mruby state reference. |
| cls | A class the class method will be undefined from. |
| name | The name of the class method to be undefined. |
Undefines a method.
Example:
# Ruby style
class ExampleClassA
def example_method
"example"
end
end
ExampleClassA.new.example_method # => example
class ExampleClassB < ExampleClassA
undef_method :example_method
end
ExampleClassB.new.example_method # => undefined method 'example_method' for ExampleClassB (NoMethodError)
// C style
#include <stdio.h>
#include <mruby.h>
mrb_value
mrb_example_method(mrb_state *mrb){
return mrb_str_new_lit(mrb, "example");
}
void
mrb_example_gem_init(mrb_state* mrb){
struct RClass *example_class_a;
struct RClass *example_class_b;
struct RClass *example_class_c;
example_class_a = mrb_define_class(mrb, "ExampleClassA", mrb->object_class);
mrb_define_method(mrb, example_class_a, "example_method", mrb_example_method, MRB_ARGS_NONE());
example_class_b = mrb_define_class(mrb, "ExampleClassB", example_class_a);
example_class_c = mrb_define_class(mrb, "ExampleClassC", example_class_b);
mrb_undef_method(mrb, example_class_c, "example_method");
}
mrb_example_gem_final(mrb_state* mrb){
}
| mrb | The mruby state reference. |
| cla | The class the method will be undefined from. |
| name | The name of the method to be undefined. |
|
extern |
Executes a sequence of mruby bytecode instructions.
This is the main bytecode interpreter loop. It takes a starting proc (begin_proc) and a pointer to the initial instruction (iseq) within that proc's instruction sequence. It then enters a loop, fetching and dispatching bytecode operations until an OP_STOP instruction is encountered, an exception occurs, or a C function call returns.
This function handles the low-level details of instruction decoding, stack manipulation, exception handling (try/catch blocks within mruby code), and calling C functions or other mruby methods.
| mrb | The mruby state. |
| begin_proc | The initial RProc whose bytecode is to be executed. While the name suggests it's the "beginning" proc, execution might involve other procs called from this one. |
| iseq | A pointer to the first bytecode instruction to execute within begin_proc's instruction sequence. |
|
extern |
Executes a mruby bytecode sequence (iseq) within the VM.
This function is a core part of the mruby execution process. It sets up the VM environment for executing the bytecode instructions associated with the given proc (Ruby procedure/method).
It initializes the stack if necessary, extends it to accommodate the required number of registers for the proc, and then calls mrb_vm_exec to actually execute the bytecode.
| mrb | The mruby state. |
| proc | The RProc object containing the bytecode (iseq) to execute. This proc represents a Ruby method or block. |
| self | The self object for the context of this execution. |
| stack_keep | The number of values to preserve on the stack from the previous context. This is used for managing nested calls and ensuring that arguments or local variables from the caller are accessible if needed, or that the stack is correctly cleared. |
Yields to a block with a single argument.
This function executes a given block (b) with a single argument (arg). It's a convenience function for the common case of yielding with one argument. The self object and class context for the block execution are determined from the block itself. Visibility checks are not strictly enforced (vis_break is FALSE).
| mrb | The mruby state. |
| b | The block (proc) to yield to. |
| arg | The single mrb_value argument to pass to the block. |
|
extern |
Yields to a block with an array of arguments.
This function executes a given block (b) with the provided arguments (argv). The self object and class context for the block execution are determined from the block itself (its captured environment). Visibility checks (public/private/protected) are not strictly enforced in the same way as mrb_yield_with_class (vis_break is FALSE).
| mrb | The mruby state. |
| b | The block (proc) to yield to. |
| argc | The number of arguments in argv. |
| argv | A pointer to an array of mrb_value arguments to pass to the block. |
|
extern |
Yields to a block with a specific self object and class context.
This function executes a given block (b) with the provided arguments (argv). The self object within the block will be self, and the class context will be c. This allows for more control over the execution environment of the block. The vis_break flag is set to TRUE, meaning visibility checks (public/private/protected) are enforced.
| mrb | The mruby state. |
| b | The block (proc) to yield to. |
| argc | The number of arguments in argv. |
| argv | A pointer to an array of mrb_value arguments to pass to the block. |
| self | The object that will be self inside the block. |
| c | The class context for the block execution. |